#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
int main() {
    int n;
    cin>>n;
    string str1, str2;
    cin>>str1>>str2;
    LL res1=0, res2=0;
    int cnt=0;
    for (int i=0; i<n; ++i) {
        if (cnt%2==0 && str1[i]=='1') {
            res1+=(1ll<<(n-1-i));
        }
        if (cnt%2==1 && str1[i]=='0') {
            res1+=(1ll<<(n-1-i));
        }
        if (str1[i]=='1') cnt++;
    }
    cnt=0;
    for (int i=0; i<n; ++i) {
        if (cnt%2==0 && str2[i]=='1') {
            res2+=(1ll<<(n-1-i));
        }
        if (cnt%2==1 && str2[i]=='0') {
            res2+=(1ll<<(n-1-i));
        }
        if (str2[i]=='1') cnt++;
    }
    cout<<abs(res1-res2)-1<<endl;
    return 0;
}
